{% extends "master.html" %}

{% block title %}Admin{% endblock %}

{% block script %}
<script type="text/javascript">
function saveCategory()
{
	document.forms['admin'].submit()
}
function delete_category(id)
{
	window.location.href = '/delete_admin?id=' + id;
}
function edit_category(id)
{
	window.location.href = '/admin?id=' + id;
}
</script>
{% endblock %}

{% block content %}
	{% if admin %}
		<form name="admin" method="POST">
			<table align="center">
				<tbody>
					<tr>
						<td>Номын төрөл</td>
						<td><input type="text" name="name" value="{{ chosen_category.name }}"></td>
						<td>
							<select name="category">
								<option></option>
								{% for maincategory in maincategory_list %}
									{% ifequal chosen_category.maincategory maincategory %}
										<option selected>{{ maincategory }}</option>
									{% else %}
										<option>{{ maincategory }}</option>
										{% endifequal %}
								{% endfor %}
							</select>
						</td>
					</tr>
					<tr>
						<td>
						<input type="button" value="Хадгалах" onclick="saveCategory()">
						</td>
					</tr>
					<table align="center">
					{% for maincategory in maincategory_list %}
						<tr>
							<td bgcolor="#AFC7C7">{{ maincategory }}</td>
						{% for category in category_list %}
							{% ifequal maincategory category.maincategory %}
							<tr>
									<td>{{ category.name }}</td>
									<td>
										<input type="button" value="Засах" onclick="edit_category({{ category.key.id }})"/>
										<input type="button" value="Устгах" onclick="delete_category({{ category.key.id }})" />
										<input type="hidden" name="chosen_category" value="{{ chosen_category.key.id }}" />
									</td>
							</tr>
							{% endifequal %}
						{% endfor %}
						</tr>
					{% endfor %}
					</table>
				</tbody>
			</table>
		</form>
	{% endif %}
{% endblock %}
{% block adminSlidebar %}{% include "adminSlidebar.html" %}{% endblock %}